import json

import requests
def start(**kwargs):
    with open('jsessionid.json', 'r', encoding='utf-8') as file:
        JSESSIONIDX=json.load(file)['JSESSIONID']
    cookies = kwargs


    headers = {
        'Host': 'gzmh.zwfw.guizhou.gov.cn',
        'sec-ch-ua': '"Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'navigate',
        'Sec-Fetch-User': '?1',
        'Sec-Fetch-Dest': 'document',
        'Referer': 'https://gzmh.zwfw.guizhou.gov.cn/login/',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        # 'Cookie': 'tempTokenKey=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiLnhormr4UiLCJhdWQiOiI5RTEwNTlDOTMzNUQ0QzdDQjhEQzc0MDBEMDNBRUNGQiIsInNlcnZlciI6Imh0dHBzOi8vZ3ptaC56d2Z3Lmd1aXpob3UuZ292LmNuL2xvZ2luLyIsInJvbGUiOiJST0xFX0FSRUEsUk9MRV9XSU5ET1ciLCJpc0luaXRpYWxQYXNzd29yZCI6IjAiLCJyZWdpb25OYW1lIjoi6LS15bee55yBIiwiaW5kdXN0cnkiOm51bGwsImFwcENvZGUiOiJkZ292LXBvcnRhbCIsIm9yZ2FuTmFtZSI6IuaWsOi_m-S6uuWRmCIsInJlZ2lvbkNvZGUiOiI1MjAwMDAiLCJpbmR1c3RyeUxpc3QiOm51bGwsIm9yZ2FuQ29kZSI6IjUyMDAwMDIwMTcwMjE2MTAwNTMwMDAwNTA3IiwiZXhwaXJhdGlvblRpbWUiOjQ5LCJncmFkZSI6IjIiLCJzdGF0dXMiOiIxIiwiaXNzIjoiaW5zcHVyIiwiaWF0IjoxNzU4MDI3MzE3LCJleHAiOjE3NTgwNTYxMTd9.-LZrqH-GckBrB2KXCL_GKNcC1jHCZZQcR8Aezrjqr92WmywRlOlRPylBnfYgulvexS1NrhgC_4ulZWpz04wO9A; userInfoKey={%22role%22:%22ROLE_AREA%2CROLE_WINDOW%22%2C%22isInitialPassword%22:%220%22%2C%22regionName%22:%22%E8%B4%B5%E5%B7%9E%E7%9C%81%22%2C%22appCode%22:%22dgov-portal%22%2C%22organName%22:%22%E6%96%B0%E8%BF%9B%E4%BA%BA%E5%91%98%22%2C%22regionCode%22:%22520000%22%2C%22phone%22:%22384d53fa06a4844cfd54260b048c33e9%22%2C%22organCode%22:%2252000020170216100530000507%22%2C%22expirationTime%22:49%2C%22name%22:%221342b48e6f8f39ea7ba36accc05b61a8%22%2C%22id%22:%229E1059C9335D4C7CB8DC7400D03AECFB%22%2C%22email%22:%223f9980534589201ab2c5f2481db36392%22%2C%22username%22:%2247d57692a252657367001b6a2ff35333%22%2C%22status%22:%221%22%2C%22isWeakPwd%22:%220%22}; pwdState=true; inspurRoleKey=ROLE_AREA; windowId=0B7CA12E92004E0ABCA9EB88F0A792E4',
    }
    #第一次重定向
    response1 = requests.get(url='https://gzmh.zwfw.guizhou.gov.cn/zhsltr/', cookies=cookies,allow_redirects=False, headers=headers)


    # from 登录子系统.utils.解构set_cookies import parse_cookie_to_simple_kv
    # re=parse_cookie_to_simple_kv(response1.headers['Set-Cookie'])
    # print(re)
    cookies['JSESSIONID']=JSESSIONIDX


    #第二次重定向
    response2 = requests.get(url=response1.headers['Location'], cookies=cookies,allow_redirects=False, headers=headers)


    #第三次重定向
    response3 = requests.get(url=response2.headers['Location'], cookies=cookies,allow_redirects=False, headers=headers)
    # print(response3.headers)

    from 登录子系统.utils.解构set_cookies import parse_cookie_to_simple_kv
    re = parse_cookie_to_simple_kv(response3.headers['Set-Cookie'])
    cookies['JSESSIONID']=re['JSESSIONID']
    #第四次重定向
    response4 = requests.get(url=response3.headers['Location'], cookies=cookies,allow_redirects=False, headers=headers)
    print(response4.text)

    return cookies

